﻿using System;
using System.Web;
using System.Web.SessionState;

/// <summary>
/// 管理员处理ashx的基类
/// </summary>
public class MyAdmin_AjaxBase : IHttpHandler, IRequiresSessionState
{
    /// <summary>
    /// 获取操作参数
    /// </summary>
    protected string operType = ReadRequest.RequestString("t");
    /// <summary>
    /// 获取当前登录用户信息
    /// </summary>
    protected Model.Manageadmin loginUserInfo = null;
    /// <summary>
    /// 初始化
    /// </summary>
    protected void Init()
    {
        //设置类型
        System.Web.HttpContext.Current.Response.ContentType = "text/html";
        //基类方法,检查登录状态,loginUserInfo可得到当前登录用户信息
        ckLogin();
    }
    /// <summary>
    /// 程序请求虚方法
    /// </summary>
    /// <param name="context"></param>
    public virtual void ProcessRequest(HttpContext context) { }
    /// <summary>
    /// 检查登录状态
    /// </summary>
    protected void ckLogin()
    {
        //获取登录信息
        loginUserInfo = BLL.CMember.ManageadminLoginInfo();
        //当前用户没有登录
        if (loginUserInfo == null)
        {
            System.Web.HttpContext.Current.Response.Redirect("/manage/admin_Login.aspx");
        }
    }
    public void alertmessage(string message)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');</script>");
    }
    public void alertmessage(string message,string jscode)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');" + jscode + "</script>");
    }
    public void alertmessageAndGoback(string message)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');history.go(-1);</script>");
    }
    public void alertmessageAndGo(string message, string url)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');window.location.href = '" + url + "';</script>");
    }
    public void alertmessageAndGo(string url)
    {
        System.Web.HttpContext.Current.Response.Write("window.location.href = '" + url + "';</script>");
    }
    public void returnmessage(string message)
    {
        System.Web.HttpContext.Current.Response.Write(message);
    }
    public void returnmessage(bool value)
    {
        System.Web.HttpContext.Current.Response.Write(value.ToString());
    }
    /// <summary>
    /// 请求重用或独占方式处理
    /// </summary>
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}